package com.dbsop.common.util;

import java.lang.reflect.Field;
import java.util.List;

public class EsStringUtils {


    public static String joinObj(String fieldName,Object[] objs,String flag){
        if (objs == null || objs.length == 0){
            return null;
        }
        flag = flag == null?"":flag;
        String joinStr = "";
        for (Object obj : objs) {
            Object fieldValue = FieldUtils.getFieldValue(obj, fieldName);
            if (fieldValue!=null){
                joinStr += fieldValue+flag;
            }
        }
        return joinStr.substring(0,joinStr.length()-flag.length());
    }

    public static String joinObj(String fieldName, List objs, String flag){
        if (objs == null || objs.size() == 0){
            return null;
        }
        flag = flag == null?"":flag;
        String joinStr = "";
        for (Object obj : objs) {
            Object fieldValue = FieldUtils.getFieldValue(obj, fieldName);
            if (fieldValue!=null){
                joinStr += fieldValue+flag;
            }
        }
        return joinStr.substring(0,joinStr.length()-flag.length());
    }
}
